//
//  MainViewController.m
//  Surfing_Platform
//
//  Created by amei on 12-4-25.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MainViewController.h"


@implementation MainViewController

@synthesize managedObjectContext = _managedObjectContext;
@synthesize mLoginBtn;
@synthesize mNameField;
@synthesize mPasswordField;

- (IBAction)OnButtonClick:(id)sender{
    if(sender == mLoginBtn){
        NSString *userName = [[NSString alloc] initWithFormat: @"%@",mNameField.text];
        NSString *pwd = [[NSString alloc] initWithFormat: @"%@",mPasswordField.text];;
        NSLog(@" username = %@   pwd == %@",userName,pwd);
        NSString *url = [[NSString alloc] initWithFormat:@"http://125.76.228.165/tianyi/index.php?controller=user&action=PhoneLogin&username=%@&password=%@",userName,pwd];
        NSLog(@"the url is : %@",url);
        HttpConnectionUtil *connectionUitl = [[HttpConnectionUtil alloc] initWithDelegate:self];
        if([connectionUitl NetworkAvisible]){
            [connectionUitl asyncConnect:url AndMethod:HTTP_REQUEST_GET MutableData:nil];
           
        }else{
            [self showDialog:@"请打开数据链接"];
        }
        
       
    }else if(sender == mLogoutBtn){
        NSLog(@"onButtonClick log out");
    }
    
}
-(void) showDialog:(NSString*) errormsg{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示"
                                                        message:errormsg
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
    [alertView show];
}
- (IBAction)textFieldDoneEditing:(id)sender{
    BOOL flag = [sender resignFirstResponder];
    NSLog(@"textFieldDoneEditing return bool = %d",flag);
}
- (IBAction)backgroundTap:(id)sender{
    NSLog(@"backgroundTap");
    BOOL flag = [mNameField resignFirstResponder];
    
    NSLog(@"namefield return bool = %d",flag);
    flag = [mPasswordField resignFirstResponder];
    NSLog(@"mPasswordField return bool = %d",flag);
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

#pragma mark - Flipside View


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showAlternate"]) {
        [[segue destinationViewController] setDelegate:self];
    }
}

- (void)dealloc
{
    [_managedObjectContext release];
    [super dealloc];
}

#pragma mark ------ DownloadHelper Delegate Method ------
-(void) ReponseCallBack:(NSString *) response{
    if(([response isEqualToString:@"failed"]) || ([response isEqualToString:@"NETWORK_INVILIBLE"])){
        [self showDialog:@"用户名或者密码错误"];
    }
}

@end
